package com.qcxy.gzy.task;

import android.app.Activity;
import android.os.AsyncTask;

import com.qcxy.gzy.view.CustomProgress;

/**
 * 网络请求基类task
 * 
 * @author scd
 *
 * @param <Params>
 *            网络请求时参数
 * @param <Progress>
 *            网络请求时进度
 * @param <Result>
 *            网络请求返回的结果
 */
public abstract class BaseAsyncTask<Params, Progress, Result> extends AsyncTask<Params, Progress, Result> {
    /** 自定义进度条 */
    private CustomProgress mProgress;
    /** 上下文 */
    private Activity       mActivity;

    public BaseAsyncTask(Activity a) {
        mActivity = a;
    }

    @Override
    protected void onPreExecute() {
        if (mProgress == null) {
            mProgress = CustomProgress.createDialog(mActivity);
        }
        if (mProgress != null) {
            mProgress.show();
        }
        super.onPreExecute();
    }

    @Override
    protected void onPostExecute(Result result) {
        if (mProgress != null && mProgress.isShowing()) {
            mProgress.dismiss();
            mProgress.cancel();
        }
        super.onPostExecute(result);
    }
}
